cmake_minimum_required(VERSION 3.10)
project(OpenSSLExample)

# 查找 OpenSSL 库
find_package(OpenSSL REQUIRED)

# 如果 OpenSSL 找到
if(OPENSSL_FOUND)
    message(STATUS "OpenSSL 库已找到")
    message(STATUS "OpenSSL include 目录: ${OPENSSL_INCLUDE_DIR}") 
    message(STATUS "OpenSSL 库文件: ${OPENSSL_LIBRARIES}")
    message(STATUS "OpenSSL 版本: ${OPENSSL_VERSION}")

    # 添加头文件搜索路径
    # 注意是 OpenSSL_INCLUDE_DIR 而不是 OpenSSL_INCLUDE_DIRS
    include_directories(${OPENSSL_INCLUDE_DIR})

    # 添加一个可执行文件
    add_executable(OpenSSLExample main.cpp)

    # 链接 OpenSSL 库
    target_link_libraries(OpenSSLExample ${OPENSSL_LIBRARIES})

    # 打印 OpenSSL 组件状态 (可选，用于调试)
    message(STATUS "OpenSSL crypto 组件: ${OPENSSL_CRYPTO_LIBRARY}")
    message(STATUS "OpenSSL ssl 组件: ${OPENSSL_SSL_LIBRARY}")

else()
    message(FATAL_ERROR "找不到 OpenSSL 库，请确保已安装并设置正确的路径")
endif()

# 处理 OpenSSL 的不同版本
if(OPENSSL_VERSION VERSION_LESS "1.1.0")
    message(WARNING "OpenSSL 版本 ${OPENSSL_VERSION} 低于 1.1.0，可能存在安全风险，建议升级")
endif()